<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Teaching Material</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../layui.css" media="all">
  <link rel="stylesheet" href="../MDASS.css" media="all">
</head>
<body style="overflow-y: scroll;">
<div class="layui-tab"><!-- TAB页 -->
  <ul class="layui-tab-title">
    <li class="layui-this">审核征订</li>
    <li>数据统计</li>
  </ul>
  <div class="layui-tab-content">
<!-- TAB1 -->
    <div class="layui-tab-item layui-show">
    <div style="margin-bottom: 5px;">          
    <ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>
<div class="layui-row">
    <div class="layui-col-md6">
  		<button id="searchApply" data-method="search" class="layui-btn" style="float: left;margin-right: 10px">搜索</button>    
  		<input name="apply_search" id="apply_search" class="layui-input" type="text" style="float: left;width: 200px" >
	</div>
</div>
	<br>
    </div>
      <table class="layui-table" id = "examineDate" lay-filter="demo" lay-data="{id: 'examineDate'}" grid = "2"></table>  
    </div>
<!-- TAB2 -->
  </div>
</div>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="examine" value='{{d.status}}' {{ d.status == '未审核' ? '' : 'style="display:none"' }}>审核</a>
</script> 
<script src="../layui.js" charset="utf-8"></script><!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script src="../jquery-3.1.1.min.js"></script>
<script>
layui.use(['table','layer','element'], function(){
	var $ = layui.jquery;
    var element = layui.element;
    var table = layui.table;
    var layer = layui.layer;
    //记录页码用于重载定位
  	var pageNum = 0;
    table.render({
        id:'examineDate',
        elem: '#examineDate',
        url:'/admin/apply/getAll',
        done: function(res, curr, count){
          pageNum = curr;
              //如果是异步请求数据方式，res即为你接口返回的信息。
              //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
        },
        cols:[[//标题栏
        {field:'id', width:150,title:'编号'},
        {field:'applySerial',width:150,title:'申请编码',sort:true},
        {field:'applyTime',title:'申请日期',sort:true},
        {field:'tSerial',width:150,title:'申请教师工号'},
        {field:'status',title:'申请状态',sort:true},
        {fixed: 'right', width:100, align:'center',title:'功能', toolbar: '#barDemo'}
        ]],
        skin:'line',
        even: true,
        page:true,
        limits:[5,10,15],
        limit:5,//limit:5 每页显示的数量
    });
    table.on('tool(demo)', function(obj){
    	var data = obj.data;
    	if(obj.event=='examine'){
    		layer.confirm('确定审核？', function(index){
            obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
            layer.close(index);
            //向服务端发送删除指令
            data.status = '已审核';
            examineApply(data.id,data.applySerial,data.applyTime,data.status,data.tSerial);
            });	
    	}
    });
    var active = {
    	search:function(){
    		var keyWord = $("#apply_search").val();
    		console.log(keyWord);
    		table.reload('examineDate',{
    			url:'/admin/apply/byKeyWord',
    			where:{
    				keyWord:keyWord
    			},
    			page:{
    				curr:1 //重新从第 1 页开始
    			}
    		});
    	}
    }
    $('.layui-btn').on('click', function(){
    	var othis = $(this), method = othis.data('method');
    	active[method] ? active[method].call(this, othis) : '';
  	});

})
function examineApply(id,applySerial,applyTime,status,tSerial){
	$.ajax({
		url:'/admin/apply/updata',
		type:"post",
		dataTypr:"json",
		data:{
			"id":id,
			"applySerial":applySerial,
			"applyTime":applyTime,
			"status":status,
			"tSerial":tSerial
		},
		success:function(result){
			console.log(result);
		},
		error:function(result){
			console.log(result);
		}
	})
}

</script>
</body>
</html>